<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="招生年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsxn">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="报考院系">
              <a-select :allowClear="true" @change="yxChange" optionFilterProp="children" showSearch v-model="queryParam.lqyxsdm">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="报考专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.lqzym">
                <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:16}" :xl="{span:8}">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExportPDF">导出PDF</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :scroll="{ x: 3000 }"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :pagination="pagination"
      @change="handleTableChange"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
    </a-card>
</div>
</template>

<script>
  // import moment from 'moment'
  import {STable} from '~'
  import {mapState} from 'vuex'

  const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable
  },
  data () {
    return {
      advanced: true,
      loading: false,
      pagination:{},
      data: [],
      // 查询参数
      queryParam: {
       zsxn:'',
        lqyxsdm:'',
       lqzym:''
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '院系代码',
          dataIndex: 'lqyxm'
        },
        {
          title: '院系名称',
          dataIndex: 'lqyxmc'
        },
        {
          title: '科目代码',
          dataIndex: 'kmbm'
        },
        {
          title: '科目名称',
          dataIndex: 'kmmc'
        },
        {
          title: '总分',
          dataIndex: 'zf'
        },
        {
          title: '总人数',
          dataIndex: 'zrs'
        },
        {
          title: '及格人数',
          dataIndex: 'jgrs'
        },
        {
          title: '及格率',
          dataIndex: 'jgl'
        },
        {
          title: '0～1',
          dataIndex: 'zero'
        },
        {
          title: '1～2',
          dataIndex: 'sf'
        },
        {
          title: '2～3',
          dataIndex: 'esf'
        },
        {
          title: '3～4',
          dataIndex: 'tsf'
        },
        {
          title: '4～5',
          dataIndex: 'ssf'
        },
        {
          title: '5～6',
          dataIndex: 'wsf'
        },
        {
          title: '6～7',
          dataIndex: 'lsf'
        },
        {
          title: '7～8',
          dataIndex: 'qsf'
        },
        {
          title: '8～9',
          dataIndex: 'bsf'
        },
        {
          title: '9～10',
          dataIndex: 'jsf'
        },
        {
          title: '10～11',
          dataIndex: 'ybf'
        },
        {
          title: '11～12',
          dataIndex: 'ybysf'
        },
        {
          title: '12～13',
          dataIndex: 'ybesf'
        },
        {
          title: '13～14',
          dataIndex: 'ybtsf'
        },
        {
          title: '14～15',
          dataIndex: 'ybssf'
        },
        {
          title: '15～16',
          dataIndex: 'ybwsf'
        },
        {
          title: '16～17',
          dataIndex: 'yblsf'
        },
        {
          title: '17～18',
          dataIndex: 'ybqsf'
        },
        {
          title: '18～19',
          dataIndex: 'ybbsf'
        },
        {
          title: '19～20',
          dataIndex: 'ybjsf'
        },
        {
          title: '20～21',
          dataIndex: 'ebf'
        },
        {
          title: '21～22',
          dataIndex: 'ebysf'
        },
        {
          title: '22～23',
          dataIndex: 'ebesf'
        },
        {
          title: '23～24',
          dataIndex: 'ebtsf'
        },
        {
          title: '24～25',
          dataIndex: 'ebssf'
        },
        {
          title: '25～26',
          dataIndex: 'ebwsf'
        },
        {
          title: '26～27',
          dataIndex: 'eblsf'
        },
        {
          title: '27～28',
          dataIndex: 'ebqsf'
        },
        {
          title: '28～29',
          dataIndex: 'ebbsf'
        },
        {
          title: '29～30',
          dataIndex: 'ebjsf'
        }
      ],
      selectMenu: {
        yx: [] // 院系
      },
      recruitEditData: {}
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    // 加载数据
    loadData(parameter = {}) {
      if(!parameter.pageNum){
        this.pagination.current = 1
        parameter.pageNum = 1
        parameter.pageSize = 10
      }
      if(!this.queryParam.zsxn)this.queryParam.zsxn = ''
      if(!this.queryParam.lqyxsdm)this.queryParam.lqyxsdm = ''
      if(!this.queryParam.lqzym)this.queryParam.lqzym = ''
      this.loading = true;
      var params = Object.assign(parameter,this.queryParam)
      this.$api.situation.customTopic(params).then(res => {
        // console.log(res)
         const pagination = { ...this.pagination
        };
        pagination.total = 0
        if (res.data && res.data.total) {
          pagination.total = res.data.total;
        }
        this.data = []
         if (res.data && res.data.rows.length) {
           this.data = res.data.rows
         }
        this.pagination = pagination;
        this.loading = false;
      })
    },
            // 分页
    handleTableChange(pagination, filters, sorter) {
      console.log(pagination);
      const pager = { ...this.pagination
      };
      pager.current = pagination.current;
      this.pagination = pager;
      this.loadData({
        pageSize: 10,
        pageNum: pagination.current
      });
    },
    // 选择招生年度
    zsndChange () {

    },
    yxChange (code) {
      this.$set(this.queryParam, 'lqzym', '')
      this.$set(this.selectMenu, 'zy', [])
      if(code){
      this.getProssion(code)
      }
    },
    getProssion(code) {
      this.$api.base.majorAll({
        lsdwh: code
      }).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    // 导出
    handleExportPDF () {
      this.$export('admissions/ssksxx/exportByFs',this.queryParam)
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
